package cn.dylan.controller;

import cn.dylan.domain.Product;
import cn.dylan.service.IProductService;
import cn.dylan.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService productService;

    @PostMapping("/save")
    public JsonResult save(@RequestBody Product product){
        try {
            productService.save(product);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        }
    }
}
